package de.tum.in.eist.poll.shared.beans;

import com.google.gwt.user.client.rpc.IsSerializable;

import de.tum.in.eist.poll.client.views.widgets.questions.QuestionWidget;

/**
 * A Question object is used to ask the User for an answer to
 * a certain question. The type of question depends on the
 * implementation of the subclass. Questions have two attributes
 * in common:
 * 
 * Each question can be optional or required. Optional questions
 * can be left out, required questions must be answered by the user.
 * A description contains the question to ask the user. This description
 * may or may not be used by subclasses.
 * 
 * A Question does furthermore yield a Widget via getWidget() which
 * is used in forms to actually get the information. The information
 * is encapsulated by an {@link Answer} object closely related the
 * a certain Question subclass.
 * 
 * @author The EIST-POLL-21 team.
 *
 */
public abstract class Question implements IsSerializable {
	
	private boolean optional;
	private String questionText;
	
	/**
	 * Dummy constructor for GWT.
	 */
	public Question() {
		optional = true;
		questionText = "?";
	}
	
	/**
	 * Initialize Question with a question text and the information
	 * whether the Question will be optional or not.
	 *  
	 * @param questionText The question text to show to the user.
	 * @param optional    Is this question optional or required?
	 */
	public Question(String questionText, boolean optional) {
		this.optional = optional;
		this.setQuestionText(questionText);
	}

	/**
	 * @return The information whether answering this question is optional or not.
	 */
	public boolean isOptional() {
		return optional;
	}
	
	/**
	 * @param questionText New question text for the old one to be replaced with.
	 */
	public void setQuestionText(String questionText) {
		this.questionText = questionText;
	}

	/**
	 * @return The questionText
	 */
	public String getQuestionText() {
		return questionText;
	}
	
	/**
	 * @return The QuestionWidget from which the answer will be extracted.
	 */
	public abstract QuestionWidget getWidget();
}